package com.alibaba.citrus.cr.unified.inventory.utils;

import java.math.BigDecimal;
import java.util.Objects;
import java.util.Optional;

/**
 * @description:
 * @author: yuhw
 * @date: 2024年01月22日 22:14
 **/
public class CompareUtil {

    public static boolean greaterThan(String origin, String target){
        return compare(origin,target) > 0;
    }
    public static boolean greaterThanOrEqual(String origin, String target){
        return compare(origin,target) >= 0;
    }

    public static boolean lessThan(String origin,String target){
        return compare(origin,target) < 0;
    }

    public static boolean lessThanOrEqual(String origin, String target){
        return compare(origin,target) <= 0;
    }
    public static boolean equal(String origin, String target){
        return compare(origin,target) == 0;
    }
    public static int compare(String origin, String target){
        BigDecimal originBigDecimal = Optional.ofNullable(origin).map(String::trim).map(BigDecimal::new).orElse(BigDecimal.ZERO);
        BigDecimal targetBigDecimal = Optional.ofNullable(target).map(String::trim).map(BigDecimal::new).orElse(BigDecimal.ZERO);
        return originBigDecimal.compareTo(targetBigDecimal);
    }

    public static <T> boolean anyOf(T target, T... source){
        for (T t : source) {
            if (Objects.equals(target,t)){
                return true;
            }
        }
        return false;
    }
}
